using UnityEngine;
using System;

public class SABattlePos
{
	public float x = 0;
	public float y = 0;

	public void setPos( float xx , float yy )
	{
		x = xx;
		y = yy;
	}

	static float getAngle( float sx , float sy , float px , float py )
	{
		float x = sx - px;
		float y = sy - py;
		
		float tan = (float)Math.Atan2( (double)y , (double)( x + 0.0001 ) );
		
		return tan;
	}


	public static int getDirection( SABattlePos pos1 , SABattlePos pos2 )
	{
		float a = getAngle( pos1.x , pos1.y , pos2.x , pos2.y );

		int direction = (int)SAMapDirectionType.COUNT;

		if ( a > 0 && a <= (float)Math.PI * 0.125f ) 
		{
			direction = (int)SAMapDirectionType.SOUTHEAST;
		}
		else if ( a > (float)Math.PI * 0.125f && a <= (float)Math.PI * 0.25f ) 
		{
			direction = (int)SAMapDirectionType.EAST;
		}
		else if ( a > (float)Math.PI * 0.25f && a <= (float)Math.PI * 0.375f ) 
		{
			direction = (int)SAMapDirectionType.EAST;
		}
		else if ( a > (float)Math.PI * 0.375f && a <= (float)Math.PI * 0.5f ) 
		{
			direction = (int)SAMapDirectionType.NORTHEAST;
		}
		else if ( a > (float)Math.PI * 0.5f && a <= (float)Math.PI * 0.625f ) 
		{
			direction = (int)SAMapDirectionType.NORTHEAST;
		}
		else if ( a > (float)Math.PI * 0.625f && a <= (float)Math.PI * 0.75f ) 
		{
			direction = (int)SAMapDirectionType.NORTH;
		}
		else if ( a > (float)Math.PI * 0.75f && a <= (float)Math.PI * 0.875f ) 
		{
			direction = (int)SAMapDirectionType.NORTH;
		}
		else if ( a > (float)Math.PI * 0.875f && a <= (float)Math.PI * 1.0f ) 
		{
			direction = (int)SAMapDirectionType.NORTHWEST;
		}
		else if ( a > (float)Math.PI * 1.0f && a <= (float)Math.PI * 1.125f ) 
		{
			direction = (int)SAMapDirectionType.NORTHWEST;
		}
		else if ( a > (float)Math.PI * 1.125f && a <= (float)Math.PI * 1.25f ) 
		{
			direction = (int)SAMapDirectionType.WEST;
		}
		else if ( a > (float)Math.PI * 1.25f && a <= (float)Math.PI * 1.375f ) 
		{
			direction = (int)SAMapDirectionType.WEST;
		}
		else if ( a > (float)Math.PI * 1.375f && a <= (float)Math.PI * 1.5f ) 
		{
			direction = (int)SAMapDirectionType.SOUTHWEST;
		}
		else if ( a > (float)Math.PI * 1.5f && a <= (float)Math.PI * 1.625f ) 
		{
			direction = (int)SAMapDirectionType.SOUTHWEST;
		}
		else if ( a > (float)Math.PI * 1.625f && a <= (float)Math.PI * 1.75f ) 
		{
			direction = (int)SAMapDirectionType.SOUTH;
		}
		else if ( a > (float)Math.PI * 1.75f && a <= (float)Math.PI * 1.875f ) 
		{
			direction = (int)SAMapDirectionType.SOUTH;
		}
		else
		{
			direction = (int)SAMapDirectionType.SOUTHEAST;
		}

		return direction;
	}

}
